//
//  OpenFlutterControllerViewController.m
//  DemoiOSApplication
//
//  Created by  androidlongs on 2021/6/4.
//


//代码清单9-20
//OpenFlutterControllerViewController.m  创建的测试类

#import "OpenFlutterControllerViewController.h"
#import "Flutter/Flutter.h"
#import "FlutterPluginRegistrant/GeneratedPluginRegistrant.h"

@interface OpenFlutterControllerViewController ()

@property(nonatomic,strong) FlutterEngine *flutterEngine;

//用来将Flutter添加到本地的View窗口
@property (weak, nonatomic) IBOutlet UIView *otherView;

@end

@implementation OpenFlutterControllerViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    FlutterEngine *engine = [[FlutterEngine alloc]initWithName:@"native_flutter" project:nil];
    [engine runWithEntrypoint:nil];
    [GeneratedPluginRegistrant registerWithRegistry:engine];
    self.flutterEngine = engine;
}

//点击按钮事件 加载Flutter
- (IBAction)openFlutterFunction:(id)sender {

    FlutterViewController *controller = [[FlutterViewController alloc]
                                         initWithEngine:self.flutterEngine
                                         nibName:nil bundle:nil];
    [self presentViewController:controller animated:true completion:nil];

}
//点击按钮事件 加载Flutter到UIView中
- (IBAction)addFlutterToView:(id)sender {
    FlutterViewController *controller = [[FlutterViewController alloc]initWithEngine:
                                         self.flutterEngine
                                         nibName:nil bundle:nil];
    controller.view.frame =CGRectMake(0,0,100,200);
    [self.otherView addSubview:controller.view];
}

@end
